package cn.wolfcode.wolf2w.business.controller;

import cn.wolfcode.wolf2w.api.domain.Answer;
import cn.wolfcode.wolf2w.api.domain.Question;
import cn.wolfcode.wolf2w.business.query.AnswerQuery;
import cn.wolfcode.wolf2w.business.query.QuestionQuery;
import cn.wolfcode.wolf2w.business.service.IAnswerService;
import cn.wolfcode.wolf2w.business.service.IQuestionService;
import cn.wolfcode.wolf2w.business.vo.QuestionCreateVO;
import cn.wolfcode.wolf2w.common.core.domain.R;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 浪兎兎
 * @since 2025-06-07 10:35
 */
@Api(value = "热门区域", description = "目的地提问模块")
@ApiResponses({
        @ApiResponse(code = 200, message = "成功"),
        @ApiResponse(code = 401, message = "未登录"),
        @ApiResponse(code = 403, message = "无权限"),
        @ApiResponse(code = 404, message = "接口未找到"),
        @ApiResponse(code = 500, message = "服务器内部异常"),
        @ApiResponse(code = 501, message = "业务异常"),
})
@RestController
@RequestMapping("destinationDoubt")
public class DestinationDoubtController {

    @Autowired
    private IQuestionService questionService;
    @Autowired
    private IAnswerService answerService;

    @GetMapping("/page")
    @ApiOperation("查询问题列表")
    public R<IPage<Question>> page(QuestionQuery qo) {
        IPage<Question> page = questionService.queryPage(qo);
        return R.ok(page);
    }

    @GetMapping("/detail/{id}")
    @ApiOperation(value = "查询单个问题", notes = "根据id查询")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "问题id", name = "id", required = true, dataType = "Long", example = "1")
    })
    public R<Question> one(@PathVariable Long id) {
        Question question = questionService.selectById(id);
        return R.ok(question);
    }

    @PostMapping("/create")
    @ApiOperation(value = "创建问题")
    public R<?> create(@RequestBody QuestionCreateVO vo) {
        questionService.create(vo);
        return R.ok();
    }

    @GetMapping("/self/answer")
    public R<IPage<Answer>> selfAnswer(AnswerQuery qo) {
        IPage<Answer> page = answerService.queryPageByUserId(qo);
        return R.ok(page);
    }

    @PostMapping("/answer")
    @ApiOperation(value = "回答问题")
    public R<?> answer(@RequestBody Answer answer) {
        answerService.answer(answer);
        return R.ok();
    }

    @PostMapping("/focus/{id}")
    @ApiOperation(value = "关注问题")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "问题id", name = "id", required = true, dataType = "Long", example = "1")
    })
    public R<?> focus(@PathVariable Long id){
        questionService.focus(id);
        return R.ok();
    }
    @PostMapping("/unfocus/{id}")
    @ApiOperation(value = "取消关注问题")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "问题id", name = "id", required = true, dataType = "Long", example = "1")
    })
    public R<?> unfocus(@PathVariable Long id){
        questionService.unfocus(id);
        return R.ok();
    }

    @PostMapping("/collect/{id}")
    @ApiOperation(value = "收藏回答")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "问题id", name = "id", required = true, dataType = "Long", example = "1")
    })
    public R<?> collect(@PathVariable Long id){
        answerService.focus(id);
        return R.ok();
    }
    @PostMapping("/uncollect/{id}")
    @ApiOperation(value = "取消收藏回答")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "问题id", name = "id", required = true, dataType = "Long", example = "1")
    })
    public R<?> uncollect(@PathVariable Long id){
        answerService.unfocus(id);
        return R.ok();
    }
    @PostMapping("/giveLike/{id}")
    @ApiOperation(value = "点赞问题")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "问题id", name = "id", required = true, dataType = "Long", example = "1")
    })
    public R<Long>  giveLike(@PathVariable Long id){
        return R.ok(questionService.giveLike(id));
    }

}
